<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" style="margin-bottom: 18px; text-align: left">
      <!--搜索框大小：layout="inline" -->
      <!--@keyup.enter.native：监听回车事件调用searchQuery方法-->
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <!--一个a-row表示大格子，一格a-col表示大格子中的小格子，小格子之间的间距gutter="24"表示-->
        <!--一格小格子占6等份span="6"-->
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="主体名称">
              <a-input placeholder="请输入主体名称" v-model="queryParam.companyNameParam"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否会员">
              <a-select placeholder="请选择是否会员" v-model="queryParam.memberFlag">
                <a-select-option :value="1">是</a-select-option>
                <a-select-option :value="0">否</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户状态">
              <a-select placeholder="请选择用户状态" v-model="queryParam.userStatus">
                <a-select-option :value="1">可用</a-select-option>
                <a-select-option :value="0">禁用</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
            <a-button type="primary" icon="reload" style="margin-left: 10px" @click="searchReset">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('用户注册')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="memberFlag" slot-scope="text">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-if="text == 0" color="red">否</a-tag>
        </template>
        <template slot="perfectFlag" slot-scope="text">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-if="text == 0" color="red">否</a-tag>
        </template>
        <template slot="userStatus" slot-scope="text">
          <a-tag v-if="text == 1" color="green">启用</a-tag>
          <a-tag v-if="text == 0" color="red">禁用</a-tag>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <njt-user-register-modal ref="modalForm" @ok="modalFormOk"></njt-user-register-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import NjtUserRegisterModal from './modules/NjtUserRegisterModal'

  export default {
    name: 'NjtUserRegisterList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      NjtUserRegisterModal
    },
    data () {
      return {
        description: '用户注册管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'主体名称',
            align:"center",
            dataIndex: 'companyName'
          },
          {
            title:'注册手机号',
            align:"center",
            dataIndex: 'mobilePhone'
          },
          {
            title:'注册时间',
            align:"center",
            dataIndex: 'registerTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'是否会员',
            align:"center",
            dataIndex: 'memberFlag',
            scopedSlots: { customRender: 'memberFlag' }
          },
          {
            title:'信息是否完善',
            align:"center",
            dataIndex: 'perfectFlag',
            scopedSlots: { customRender: 'perfectFlag' }
          },
          {
            title:'信息完善时间',
            align:"center",
            dataIndex: 'perfectTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'试用到期时间',
            align:"center",
            dataIndex: 'probationTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'购买会员时间',
            align:"center",
            dataIndex: 'memberTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'会员过期时间',
            align:"center",
            dataIndex: 'memberExpiredTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'用户状态',
            align:"center",
            dataIndex: 'userStatus',
            scopedSlots: { customRender: 'userStatus' }
          },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createBy'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'修改人',
            align:"center",
            dataIndex: 'updateBy'
          },
          {
            title:'更新时间',
            align:"center",
            dataIndex: 'updateTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/user/njtUserRegister/list",
          delete: "/user/njtUserRegister/delete",
          deleteBatch: "/user/njtUserRegister/deleteBatch",
          exportXlsUrl: "/user/njtUserRegister/exportXls",
          importExcelUrl: "user/njtUserRegister/importExcel",
          
        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>